//
//  RangeWebsiteController.m
//  yameishe3
//
//  Created by pro on 2017/3/7.
//  Copyright © 2017年 yameishe. All rights reserved.
//

#import "RangeWebsiteController.h"
#import "AddRangeWebsiteController.h"
#import "NomalTitleCell.h"
@interface RangeWebsiteController ()<UITableViewDataSource,UITableViewDelegate>
{
    __weak IBOutlet UITableView *_tableView;
    NSArray *_websiteArray;
}
@end

@implementation RangeWebsiteController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self controllerSetting];
    
   
    _websiteArray = [[NSArray alloc]initWithObjects:@"不限",@"全国门户",@"垂直行业",@"地方门户",nil];
    _tableView.tableFooterView = [[UIView alloc]init];
    [_tableView registerNib:[UINib nibWithNibName:@"NomalTitleCell"bundle:nil] forCellReuseIdentifier:@"NomalTitleCell"];
    
}
-(void)setConditionDic:(NSDictionary *)conditionDic
{
    _conditionDic = conditionDic;
    self.title = _conditionDic[@"name"];
}
-(void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    [_tableView reloadData];
}
-(void)viewWillDisappear:(BOOL)animated {
    // 反注册键盘
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)addWebsiteRange:(id)sender
{
    AddRangeWebsiteController *vc = [[UIStoryboard storyboardWithName:@"Range" bundle:nil] instantiateViewControllerWithIdentifier:@"AddRangeWebsiteController"];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark -- UITableViewDataSource,UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NomalTitleCell* cell = [tableView dequeueReusableCellWithIdentifier:@"NomalTitleCell"];
    [cell setTitle:_dataArray[indexPath.row][@"name"]];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (_callbackDidSelect) {
        _callbackDidSelect(_conditionDic,_dataArray[indexPath.row]);
    }
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
